<template>
  <div class="boxs" style="padding-bottom: 48px">
    <div ref="titlesBox" style="min-height: 188px">
      <titles :title="props.info.text" />
      <div class="subTitle" v-if="props.info.subTitle">——{{ props.info.subTitle }}</div>
      <div class="text-max-box">
        <textMax v-if="props.info.remarks" :data="props.info.remarks" :maxLen="109" />
      </div>
    </div>
    <div
      v-for="(item, index) in props.info.children"
      :key="item.id"
      class="exhibits-list"
      @mouseenter="imgEnter(index, props.info.children)"
      @mouseleave="imgLeave(index, props.info.children)"
    >
      <div v-if="index % 2 == 0" class="item-box">
        <div class="item" ref="itemLeft" @click="pathChild(props.info, index)" style="cursor: pointer">
          <img
            class="item-left"
            :src="urls + item.value + '?imageView2/1/w/680/h/420/format/webp'"
            alt=""
            v-if="item.value"
          />

          <UnitImageNull v-else></UnitImageNull>
          <!-- <img class="item-left" src="http://101.34.143.36:8890/api/image/387939155165253/h_420,w_680" alt="" v-else /> -->
          <div class="shadow"></div>
        </div>

        <div class="item-right" ref="itemRight">
          <div style="margin-bottom: 32px">
            <span
              :class="'titleText' + item.id"
              class="right-title1"
              :style="{
                color: store.styleInfo.fontColor,
              }"
            >
              {{ item.text }}
            </span>
            <div class="line" :class="'line' + item.id"></div>
            <div class="subTitle unit-subTitle" v-if="item.subTitle">——{{ item.subTitle }}</div>
          </div>

          <span
            :style="{
              fontSize: store.styleInfo.contentSize,

              color: '#666',
            }"
            class="text-ov-hid-style"
            >{{ item.remarks }}</span
          >
          <div
            @click="pathChild(props.info, index)"
            :style="{
              fontSize: store.styleInfo.mintitleSize,
              color: '#fff',
            }"
            class="left-btn flex-c-c-c"
          >
            <div class="btn-img">
              <buttonIcon />
            </div>
            <span>查看单元</span>
          </div>
        </div>
      </div>
      <div v-else class="item-box">
        <div class="item-right" ref="itemRight">
          <div style="margin-bottom: 32px">
            <span
              :class="'titleText' + item.id"
              class="right-title1"
              :style="{
                color: store.styleInfo.fontColor,
              }"
            >
              {{ item.text }}
            </span>
            <div class="line" :class="'line' + item.id"></div>
            <div class="subTitle unit-subTitle" v-if="item.subTitle">——{{ item.subTitle }}</div>
          </div>

          <span
            :style="{
              fontSize: store.styleInfo.contentSize,

              color: '#666',
            }"
            class="text-ov-hid-style"
            >{{ item.remarks }}</span
          >
          <div
            @click="pathChild(item, index)"
            :style="{
              fontSize: store.styleInfo.mintitleSize,
              color: '#fff',
            }"
            class="left-btn flex-c-c-c"
          >
            <div class="btn-img">
              <buttonIcon />
            </div>
            <span>查看单元</span>
          </div>
        </div>
        <div class="item" ref="itemLeft" @click="pathChild(item, index)" style="cursor: pointer">
          <img
            class="item-left"
            :src="urls + item.value + '?imageView2/1/w/680/h/420/format/webp'"
            alt=""
            v-if="item.value"
          />
          <UnitImageNull v-else></UnitImageNull>
          <!-- <img class="item-left" src="http://101.34.143.36:8890/api/image/387939155165253/h_420,w_680" alt="" v-else /> -->
          <div class="shadow"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// @ts-nocheck
import { pathList, pathListLoop } from '../route';
import { urls } from '@/utils/request/upload';
import titles from '@/components/title/title.vue';
import buttonIcon from '@/components/title/buttonIcon.vue';
import textMax from './component/textMax2.vue';
import { onMounted, ref } from 'vue';
import { useProjectStore } from '@/store';
import { useRouter, useRoute } from 'vue-router';
import { imgEnter, imgLeave } from './component/hover';
import UnitImageNull from '@/components/unitImageNull/unitImageNull.vue';
const router = useRouter();
const route = useRoute();
const store = useProjectStore();
const titlesBox = ref(null);
const itemLeft = ref(null);
const itemRight = ref(null);
const props = defineProps({
  info: {
    type: Object,
  },
});
const pathChild = (e: any, index?: number) => {
  store.setchildModel(e);
  store.setCurrent(index);
  router.push({
    name: route.meta.loopType ? pathListLoop[8] : pathList[8],
    query: { current: index, childId: props.info.id },
  });
};
onMounted(() => {
  animation();
  animation1();
  console.log(itemLeft.value[0]);
});
const animation = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        // console.log('c', exhibitsBox.value);
        titlesBox.value.classList.add('animation-box6');

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (titlesBox.value) {
        //   titlesBox.value.classList.remove('animation-box6');
        // }
      }
    });
  });
  observer.observe(titlesBox.value);
};
const animation1 = () => {
  let canTrigger = true; // 标记是否可以触发

  const observer = new IntersectionObserver((entries) => {
    entries.forEach((entry) => {
      if (entry.isIntersecting && canTrigger) {
        // 当元素进入视窗口时触发的代码s
        // console.log('c', itemLeft.value[0]);/
        itemLeft.value[1].classList.add('animation-box');
        setTimeout(() => {
          itemLeft.value[0].classList.add('animation-box');
        }, 300);
        setTimeout(() => {
          itemRight.value[0].classList.add('animation-box6');
          itemRight.value[1].classList.add('animation-box6');
        }, 600);

        // 设置一个延迟时间，防止频繁触发
        canTrigger = false;
        setTimeout(() => {
          canTrigger = true;
        }, 500); // 设置延迟时间为 500 毫秒
      } else {
        // if (itemLeft.value.length > 0) {
        //   itemLeft.value[0].classList.remove('animation-box');
        //   itemLeft.value[1].classList.remove('animation-box');
        //   itemRight.value[0].classList.remove('animation-box6');
        //   itemRight.value[1].classList.remove('animation-box6');
        // }
      }
    });
  });
  observer.observe(itemLeft.value[0]);
};
</script>

<style lang="less" scoped>
@import './index.less';
.exhibits-box {
  height: 1066px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.exhibits-text {
  width: 50%;
  margin-bottom: 50px;
}
.exhibits-list {
  width: 1180px;
  margin-bottom: 32px;
}

.item-box {
  display: flex;
  width: 100%;
}
.item-left {
  // width: 46%;
  height: auto;

  img {
    width: 100%;
    height: auto;
  }
}
.item-right {
  display: flex;
  flex-direction: column;
  justify-content: center;

  flex: 1;
  padding: 0px 50px;
  opacity: 0;
}
.right-title1 {
  font-family: SourceHanSerifCN-Bold;
  font-size: 20px !important;
  line-height: 30px;
}
.text-ov-hid-style {
  line-height: 32px;
  font-size: 16px;
  margin-bottom: 50px;
  -webkit-line-clamp: 3;
}
.item {
  position: relative;
  width: 680px;
  height: 420px;
  overflow: hidden;
  opacity: 0;

  img {
    transition: all 0.5s;
  }
}
.shadow {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  background: rgba(0, 0, 0, 0);
  transition: all 0.5s;
  z-index: 99;
}
.item-box:hover img {
  transform: scale(1.1);
}
.item-box:hover .shadow {
  background: rgba(0, 0, 0, 0.4);
}
.line {
  width: 0px;
  height: 2px !important;
  background: #000;
  transform: all 0.5s;
}
// .item-box:hover .line {
//   width: 36px;
// }
.text-max-box {
  width: 900px;
  margin-top: 20px;
  :deep(.tj) {
    line-height: 32px;
  }
}
.left-btn {
  width: 165px;
  height: 48px;
  margin-top: 0;
}
.subTitle {
  text-align: center;
}
.unit-subTitle {
  text-align: left;
}
</style>
